home *** CD-ROM | disk | FTP | other *** search
- unit Unit2;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- ShellAPI, StdCtrls;
-
- const
- wm_AppBarMessage = wm_User;
-
- type
- TForm1 = class(TForm)
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure FormShow(Sender: TObject);
- procedure FormActivate(Sender: TObject);
- private
- { Private declarations }
- abd: TAppBarData;
- function GetRequestRect: TRect;
- procedure WMAppBarMessage(var Msg: TMessage); message wm_AppBarMessage;
- procedure WMWindowPosChanged(var Msg: TWMWindowPosMsg); message WM_WindowPosChanged;
- procedure WMMoving(var Msg: TMessage); message WM_Moving;
- procedure WMExitSizeMove(var Msg: TMessage); message WM_ExitSizeMove;
- property RequestRect: TRect read GetRequestRect;
- public
- { Public declarations }
- procedure CreateParams(var Params: TCreateParams); override;
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- var
- F: TextFile;
-
- {$R *.DFM}
-
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- // fill the AppBarData data structure
- abd.cbSize := sizeof(abd);
- abd.hWnd := Handle;
- abd.uCallBackMessage := wm_AppBarMessage;
- // always start along bottom edge
- abd.uEdge := ABE_BOTTOM;
- abd.rc := RequestRect;
- abd.lParam := 0;
- SHAppBarMessage(ABM_NEW, abd);
- end;
-
- procedure TForm1.FormDestroy(Sender: TObject);
- begin
- SHAppBarMessage(ABM_REMOVE, abd);
- end;
-
- procedure TForm1.FormShow(Sender: TObject);
- begin
- ShowWindow(Application.Handle, SW_HIDE);
- SHAppBarMessage(ABM_QUERYPOS, abd);
- abd.rc.Top := abd.rc.Bottom - Height;
- SHAppBarMessage(ABM_SETPOS, abd);
- SetBounds(abd.rc.Left, abd.rc.Top, abd.rc.Right-abd.rc.Left, abd.rc.Bottom-abd.rc.Top);
- end;
-
- procedure TForm1.FormActivate(Sender: TObject);
- begin
- SHAppBarMessage(ABM_ACTIVATE, abd);
- end;
-
- procedure TForm1.CreateParams(var Params: TCreateParams);
- begin
- inherited CreateParams(Params);
- if Params.ExStyle and WS_EX_TOOLWINDOW = 0 then
- Params.ExStyle := Params.ExStyle + WS_EX_TOOLWINDOW;
- end;
-
- function TForm1.GetRequestRect: TRect;
- begin
- // set the requested Rect
- Result.Left := 0;
- Result.Top := Screen.Height - 50;
- Result.Right := Screen.Width;
- Result.Bottom := Screen.Height;
- case abd.uEdge of
- ABE_TOP: begin
- Result.Left := 0;
- Result.Top := 0;
- Result.Right := Screen.Width;
- Result.Bottom := 50;
- end;
- ABE_LEFT: begin
- Result.Left := 0;
- Result.Top := 0;
- Result.Right := 50;
- Result.Bottom := Screen.Height;
- end;
- ABE_RIGHT: begin
- Result.Left := Screen.Width-50;
- Result.Top := 0;
- Result.Right := Screen.Width;
- Result.Bottom := Screen.Height;
- end;
- end;
- end;
-
- procedure TForm1.WMAppBarMessage(var Msg: TMessage);
- begin
- // hide when fullscreen apps are displayed
- if Msg.wParam = ABN_FULLSCREENAPP then
- if Msg.lParam <> 0 then Hide else Show;
-
- if Msg.wParam = ABN_POSCHANGED then
- begin
- // fill the AppBarData data structure
- abd.rc := RequestRect;
- SHAppBarMessage(ABM_QUERYPOS, abd);
- case abd.uEdge of
- ABE_TOP: abd.rc.Bottom := abd.rc.Top + 50;
- ABE_LEFT: abd.rc.Right := abd.rc.Left + 50;
- ABE_RIGHT: abd.rc.Left := abd.rc.Right - 50;
- ABE_BOTTOM: abd.rc.Top := abd.rc.Bottom - 50;
- end;
- SHAppBarMessage(ABM_SETPOS, abd);
- SetBounds(abd.rc.Left, abd.rc.Top, abd.rc.Right-abd.rc.Left, abd.rc.Bottom-abd.rc.Top);
- end;
- end;
-
- procedure TForm1.WMWindowPosChanged(var Msg: TWMWindowPosMsg);
- begin
- // must send this message to maintain correct Z-order
- SHAppBarMessage(ABM_WINDOWPOSCHANGED, abd);
- inherited;
- end;
-
- procedure TForm1.WMMoving(var Msg: TMessage);
- var
- P: TPoint;
- begin
- GetCursorPos(P);
-
- if (P.Y < Screen.Height/Screen.Width*P.X) and
- (P.Y < -(Screen.Height/Screen.Width*P.X)+Screen.Height) then
- begin
- abd.uEdge := ABE_TOP;
- abd.rc := RequestRect;
- SHAppBarMessage(ABM_QUERYPOS, abd);
- abd.rc.Bottom := abd.rc.Top + 50;
- PRect(Msg.lParam)^ := abd.rc;
- end;
-
- if (P.Y >= Screen.Height/Screen.Width*P.X) and
- (P.Y < -(Screen.Height/Screen.Width*P.X)+Screen.Height) then
- begin
- abd.uEdge := ABE_LEFT;
- abd.rc := RequestRect;
- SHAppBarMessage(ABM_QUERYPOS, abd);
- abd.rc.Right := abd.rc.Left + 50;
- PRect(Msg.lParam)^ := abd.rc;
- end;
-
- if (P.Y >= Screen.Height/Screen.Width*P.X) and
- (P.Y >= -(Screen.Height/Screen.Width*P.X)+Screen.Height) then
- begin
- abd.uEdge := ABE_BOTTOM;
- abd.rc := RequestRect;
- SHAppBarMessage(ABM_QUERYPOS, abd);
- abd.rc.Top := abd.rc.Bottom - 50;
- PRect(Msg.lParam)^ := abd.rc;
- end;
-
- if (P.Y < Screen.Height/Screen.Width*P.X) and
- (P.Y >= -(Screen.Height/Screen.Width*P.X)+Screen.Height) then
- begin
- abd.uEdge := ABE_RIGHT;
- abd.rc := RequestRect;
- SHAppBarMessage(ABM_QUERYPOS, abd);
- abd.rc.Left := abd.rc.Right - 50;
- PRect(Msg.lParam)^ := abd.rc;
- end;
-
- inherited;
- end;
-
- procedure TForm1.WMExitSizeMove(var Msg: TMessage);
- begin
- SetBounds(abd.rc.Left, abd.rc.Top, abd.rc.Right-abd.rc.Left, abd.rc.Bottom-abd.rc.Top);
- SHAppBarMessage(ABM_SETPOS, abd);
- inherited;
- end;
-
-
- initialization
- AssignFile(F, 'c:\temp\debug.log');
- Rewrite(F);
- finalization
- CloseFile(F);
- end.
-